﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows;
using System.Globalization;

namespace RecommendatioNetwork.View.Converter
{
    class RatingComboBoxToUintConverter : IValueConverter
    {
       
        //viene invocato al passaggio dalla fonte dati verso l'elelmento di user Interface
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return "Nessuna valutazione";
            uint cbi = System.Convert.ToUInt16(value);
            try{
                if(cbi==1)
                    return "Scadente";
                if(cbi==2)
                    return "Mediocre";
                if(cbi==3)
                    return "Sufficiente";
                if(cbi==4)
                    return "Buono";
                if(cbi==5)
                    return "Ottimo";
            }catch(Exception ee){MessageBox.Show(ee.ToString());}
            return "Nessuna valutazione";
        
        }

        //viene invocato al passaggio dalla user Interface alla fonte dati
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {

            if (value == null)
                return 0;
            string cbi = value as string;
            try{
                if(string.Equals(cbi, "Scadente", StringComparison.InvariantCultureIgnoreCase))
                    return (uint)1;
                if(string.Equals(cbi, "Mediocre", StringComparison.InvariantCultureIgnoreCase))
                    return (uint)2;
                if(string.Equals(cbi, "Sufficiente", StringComparison.InvariantCultureIgnoreCase))
                    return (uint)3;
                if(string.Equals(cbi, "Buono", StringComparison.InvariantCultureIgnoreCase))
                    return (uint)4;
                if (string.Equals(cbi, "Ottimo", StringComparison.InvariantCultureIgnoreCase))
                    return (uint)5;
            }catch(Exception ee){MessageBox.Show(ee.ToString());}
            return (uint)0;
        }
    }
}






